﻿<?php
/*********************************************************************\
* This File is a part of BH-PANEL (Breizh-Heberg Panel v2.1)
* Copyright (C) 2008-2009 the BH Developpers : Vincent Giersch <mail@vincordi.fr>, Cyprien Laleau <fanning.fr@gmail.com> and Edwin Cabiten <marmottes44@hotmail.fr>
* See file AUTHORS to get more informations

* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
/*********************************************************************/

include ROOT.'php/lib/offres_inc.php';
include ROOT.'php/lib/servers.php';
if(isset($_GET['offre'])) {
	if(($_GET['offre'] == 0) OR ($_GET['offre'] == 1) OR ($_GET['offre'] == 2) OR ($_GET['offre'] == 3)) {
		if(isset($_POST['commander'])) {
			if(($_POST['commander'] == 1) OR ($_POST['commander'] == 3) OR ($_POST['commander'] == 6) OR ($_POST['commander'] == 12)) { $mois_commande = intval($_POST['commander']); }
			else { $mois_commande = 1; }

			$_SESSION['commande_heberg_duree'] = $mois_commande;
			$_SESSION['commande_heberg_offre'] = intval($_GET['offre']);
			if($_GET['offre'] == 3) {
				$prix = $surmesure['espacedisk'][$_POST['espacedisk']];
				$prix = $prix + $surmesure['bandepassante'][$_POST['bandepassante']];
				$prix = $prix + $surmesure['bases_mysql'][$_POST['bases_mysql']];
				$prix = $prix + $surmesure['comptes_mails'][$_POST['comptes_mails']];
				$prix = $prix + $surmesure['alias_mails'][$_POST['alias_mails']];
				$prix = $prix + $surmesure['user_ftp'][$_POST['user_ftp']];
				$prix = $prix + $surmesure['doms'][$_POST['doms']];
				$_SESSION['commande_heberg_surmes'] = array(
					"espacedisk" => intval($_POST['espacedisk']),
					"bandepassante" => intval($_POST['bandepassante']),
					"user_ftp" => intval($_POST['user_ftp']),
					"bases_mysql" => intval($_POST['bases_mysql']),
					"comptes_mails" => intval($_POST['comptes_mails']),
					"alias_mails" => intval($_POST['alias_mails']),
					"doms" => intval($_POST['doms']),
					"prix" => $prix,
					);
			}
			if(isset($_SESSION['u_nic'])) {
				if($deja_heb_gratuit['deja'] == 0) {
					$title = "Continuer";
					$tplinc = "Offres/offres-hebergement-commande-3";
				}
				$parse = 1;
			}
			else {
				$title = "Pour valider votre commande, vous devez vous identifier";
				$tplinc = "Offres/offres-hebergement-commande-0";
				$parse = 1;
			}
		}
		else {
			$offre_id = intval($_GET['offre']);
			
			$title = "Hébergements Mutualisés";
			$tplinc = "Offres/offres-hebergement-details-".$offre_id;
			$parse = 1;
			if($offre_id < 3) {
				$infosoffre = mysql_fetch_array(query("SELECT offres.*, offre_heberg.* FROM offres LEFT JOIN offre_heberg ON offres.id = offre_heberg.id_offre WHERE offres.id = '".$offre_id."'"));
				// Convertion de l'espace disk et bp
				if($infosoffre['espacedisk'] >= 1024) { $disk =( $infosoffre['espacedisk']/1024).'Go'; }
				else { $disk = $infosoffre['espacedisk'].'Mo'; }
				if($infosoffre['bandepassante'] >= 1024) { $bp =( $infosoffre['bandepassante']/1024).'Go'; }
				else { $bp = $infosoffre['bandepassante'].'Mo'; }
				// Doms
				if($infosoffre['doms'] == "") { $infosoffre['doms'] = "Illimités"; }
				if($infosoffre['freedom'] == "") { $infosoffre['freedom'] = "0"; }
				// Prix
				$prix_3 = number_format(3*$infosoffre['prix'], 2, '.', '');
				$prix_6 = number_format(6*$infosoffre['prix'], 2, '.', '');
				$prix_12 = number_format(12*$infosoffre['prix'], 2, '.', '');

				// Assign
				$tpl->assign(array(
					'espace_disk' => $disk,
					'bp' => $bp,
					'ftp' => $infosoffre['user_ftp'],
					'mysql_bases' => $infosoffre['bases_mysql'],
					'mysql_connex' => $infosoffre['connect_mysql'],
					'mail_comptes' => $infosoffre['comptes_mails'],
					'mail_alias' => $infosoffre['alias_mails'],
					'dom_ext' => $infosoffre['doms'],
					'dom_inc' => $infosoffre['freedom'],
					'prix' => $infosoffre['prix'],
					'prix_3' => $prix_3,
					'prix_6' => $prix_6,
					'prix_12' => $prix_12,
					'naff_commande' => intval($_GET['ncommande']),
					'disp' => $infosoffre['disp']
				));
			}
			else {
				$tpl->assign(array(
					'surmes' => $surmesure,
					'load' => "sur_mes()"));
			
			}
		}
	}
}
else {
	$title = "Hébergements Mutualisés";
	$tplinc = "Offres/offres-hebergement-tarifs";
	$parse = 1;

}

?>
